package com.timi_licai.timi_licai_account.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.timi_licai.timi_licai_account.R;
import com.timi_licai.timi_licai_account.model.ShowCategory;

import java.util.List;

/**
 * 显示分类的GridView的Adapter
 */
public class ShowCategoryAdapter extends BaseAdapter {
    private List<ShowCategory> txtList;
    private Context context;

    public ShowCategoryAdapter(Context context, List<ShowCategory> txtList) {
        this.txtList = txtList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return txtList.size();
    }

    @Override
    public Object getItem(int position) {
        return txtList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_choose_category, parent, false);
        TextView textView = (TextView) view.findViewById(R.id.txt_show_category);
        ImageView imageView = (ImageView) view.findViewById(R.id.img_show);

        if (position == txtList.size() - 1) {
            textView.setText("添加分类");
            imageView.setImageResource(R.drawable.type_big_99999);
        }
        ShowCategory showCategory = txtList.get(position);
        textView.setText(showCategory.getTypeName());

        view.setTag("categoryGridView");
        return view;
    }

    private static class ViewHolder {
        public TextView textView;
        public ImageView imgView;
    }
}
